home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTFHDX / HDBENCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  4.0 KB  |  193 lines

  1. #include    <osbind.h>
  2. #include    "define.h"
  3. #include    "lrwabs.h"
  4.  
  5.  
  6. long        total, bsize, ostack, start, btime, tleft,
  7.         tsect, hdsiz, rate, time, timesup, avg;
  8. unsigned int    pdev, scnt;
  9. char        *rbuf, show[10], key;
  10.  
  11.  
  12. main(argc, argv)
  13. int    argc;
  14. char    *argv[];
  15. {
  16.     register long    clk_in, clk_out, *hz200v;
  17.     register int    ret;
  18.  
  19.     Cconout(ESC); Cconout('H');    /* home cursor */
  20.  
  21.     /*
  22.      * printfs are buffered, put \n at end to flush it 
  23.      * or call fflush(stdout) after the printfs
  24.      */
  25.     if (argc <= 1) {        /* defaults */
  26.         pdev = 9;        /* unit 9  (SCSI unit 1) */
  27.         timesup = 60000L;    /* 5 minutes (in hz200 ticks) */
  28.         printf("\nHit ESC or test will run for 5 minute(s)\n\r\n"); 
  29.     } else {
  30.         pdev = atoi(argv[1]);
  31.         timesup = (long)atoi(argv[2]) * 12000L;
  32.         printf("\nHit ESC or test will run for %s minute(s)\n\r\n", 
  33.             argv[2]);
  34.     }
  35.  
  36.     bsize = Malloc(-1L);
  37.     rbuf = (char *)Malloc(bsize);
  38.     scnt = bsize >> 9;
  39.     total = tsect = start = 0L;
  40.     
  41.     ostack = Super(NULL);
  42.     hz200v = (long *)0x4ba;
  43.     
  44.     if (pdev < 8)
  45.         printf("Timing ACSI unit %d\n\r", pdev);
  46.     else if (pdev < 16)
  47.         printf("Timing SCSI unit %d\n\r", pdev-8);
  48.     else
  49.         printf("Timing IDE unit %d\n\r", pdev-16);
  50.  
  51.     printf("Number of sectors per read: %d\n\r", scnt);
  52.  
  53.     pdev += 2;
  54.  
  55.     /* find hard disk size */
  56.     if (Rwabs(PHYSREAD, rbuf, 1, 0, pdev) != 0) {
  57.         printf("\n\rRead error\!\n\r");
  58.         goto end;
  59.     }
  60.     hdsiz = *(long *)(rbuf + 0x1c2);
  61.  
  62.     btime = *hz200v;
  63.     avg = 0L;
  64.     while (1) {
  65.             /* Check for keyboard input */
  66.             if ((key = chkeybd()) == ESC) {
  67.             goto end;
  68.             }
  69.  
  70.         if (start + (long)scnt >= hdsiz) {
  71.             start = 0L;
  72.         }
  73.  
  74.         ltoa(start, show);
  75.         printf("Starting sector #: %s          \n\r", show);
  76.         clk_in = *hz200v;
  77.         ret = Lrwabs(PHYSREAD, rbuf, scnt, start, pdev);
  78.         clk_out = *hz200v;
  79.  
  80.         if (ret != 0) {
  81.             printf("\n\rRead Error\!");
  82.             goto end;
  83.         } else {
  84.             time = clk_out - clk_in;
  85.             total += time;
  86.             tsect += scnt;
  87.             start += scnt;
  88.             ltoa(time, show);
  89.             printf("Time taken (in 200Hz ticks): %s      \n\r", 
  90.                 show);
  91.             rate = ((unsigned long)scnt << 9) * 200 / time;
  92.             if (avg != 0L)
  93.                 avg = (avg + rate) / 2;
  94.             else
  95.                 avg = rate;
  96.             ltoa(rate, show);
  97.             printf("Average rate (in bytes/sec): %s      \n\r", 
  98.                 show);
  99.         }
  100.  
  101.         
  102.         if ((tleft = timesup - (*hz200v-btime)) <= 0) {
  103.             printf("Time's up\!                          \n\r");
  104.             goto end;
  105.         }
  106.         tleft /= 200L;
  107.         ltoa(tleft, show);
  108.         printf("Time left (in sec): %s          \n\r", show);
  109.         Cconout(ESC); Cconout('A');
  110.         Cconout(ESC); Cconout('A');
  111.         Cconout(ESC); Cconout('A');
  112.         Cconout(ESC); Cconout('A');
  113.     }
  114. end:
  115.     printf("\n\n\n\n\nGAME OVER\!\!\n\r");
  116.     Super(ostack);
  117.     Mfree(rbuf);
  118.     while(!Cconis())
  119.         ;
  120. }
  121.  
  122.  
  123. ltoa(inword, numbuf)            
  124. long inword;
  125. char numbuf[];
  126. {    
  127.     unsigned long temp1, value;
  128.     register int i, j;
  129.     char tmpbuf[10];
  130.     register char *ascbuf;
  131.     
  132.     ascbuf = numbuf;
  133.     i = 0;
  134.  
  135.     if (!inword)            /* if the value is non zero  */
  136.     *ascbuf++ = '0';
  137.     else {
  138.     value = inword;
  139.     while(value) {
  140.         temp1 = value % 10;        /*  find the remainder    */
  141.         temp1 += 0x0030;        /*  convert to ASCII    */
  142.         tmpbuf[i++] = temp1;    /*  buffer is reverse    */
  143.         value = value / 10;
  144.     }
  145.  
  146.     for (j = i-1; j >= 0; j--)     /* reverse it back    */
  147.         *ascbuf++ = tmpbuf[j];
  148.     }
  149.  
  150.     *ascbuf = 0;            /* end of string mark    */
  151.     return;
  152. }
  153.  
  154.  
  155.  
  156. atoi(ptr)
  157. char *ptr;
  158. {
  159.     register int n;
  160.  
  161.     for (n = 0; (*ptr >= '0' && *ptr <= '9'); ptr++)
  162.     n = (10 * n) + *ptr - '0'; 
  163.  
  164.     return (n);
  165. }
  166.  
  167.  
  168.  
  169. /*
  170.  *  Check if any key is input from the keyboard.
  171.  *    Key code looking for:
  172.  *        Escape - to stop the procedure
  173.  *        Any other or no key - no effect.
  174.  *    Return:
  175.  *        NOKEY - if no key is input, or key input is not
  176.  *            what we are looking for.
  177.  *        or ESC
  178.  */
  179. char
  180. chkeybd()
  181. {
  182.     char key;        /* key being input */
  183.  
  184.     if (Cconis()) {        /* 2: CONSOLE */
  185.         if((key = (char)Cconin()) != ESC)
  186.             key = NOKEY;
  187.     } else {
  188.         key = NOKEY;
  189.     }
  190.     return key;
  191. }
  192.  
  193.